package com.edu.exam.enums.grading;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 成绩操作类型枚举
 *
 * <p>管理成绩记录的操作类型，包括创建、更新、删除、提交、撤回、审核、驳回等操作。</p>
 *
 * @author System
 * @version 1.0.0
 * @since 2025-11-14
 */
public enum GradeOperationType implements BaseEnum {

    /** 创建 */
    CREATE("CREATE", "创建"),

    /** 更新 */
    UPDATE("UPDATE", "更新"),

    /** 删除 */
    DELETE("DELETE", "删除"),

    /** 提交 */
    SUBMIT("SUBMIT", "提交"),

    /** 撤回 */
    WITHDRAW("WITHDRAW", "撤回"),

    /** 审核 */
    REVIEW("REVIEW", "审核"),

    /** 驳回 */
    REJECT("REJECT", "驳回"),

    /** 批准 */
    APPROVE("APPROVE", "批准"),

    /** 导入 */
    IMPORT("IMPORT", "导入"),

    /** 导出 */
    EXPORT("EXPORT", "导出"),

    /** 修改 */
    MODIFY("MODIFY", "修改"),

    /** 查询 */
    QUERY("QUERY", "查询");

    private final String code;
    private final String description;

    GradeOperationType(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 根据编码查找枚举值
     *
     * @param code 业务编码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果编码无效
     */
    public static GradeOperationType fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException("Grade operation type code cannot be null or empty");
        }

        for (GradeOperationType type : values()) {
            if (type.getCode().equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown grade operation type code: " + code);
    }

    /**
     * 根据描述查找枚举值
     *
     * @param description 显示描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述无效
     */
    public static GradeOperationType fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            throw new IllegalArgumentException("Grade operation type description cannot be null or empty");
        }

        for (GradeOperationType type : values()) {
            if (type.getDescription().equals(description)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown grade operation type description: " + description);
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}